<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Home\Controller;
use User\Api\UserApi;

/**
 * 用户控制器
 * 包括用户中心，用户登录及注册
 */
class GoodsDetailController extends HomeController {

	/* 商品详情 */
	public function detail(){

		// echo I('get.goods_id');
		$goods = D('image');
		$data = $goods->showdetail();
		// echo '<pre>';
		// 	print_r($data);
		// echo '<pre>';
		// echo $data['a'];
		$this->assign('data' , $data['samegoods']);
		$this->assign('count' , $data['a']);
		$this->assign('sum' , $data['sum']);
		$this->assign('gname' , $data['gname']);
		$this->assign('evalist' , $data['evalist']);
		$this->assign('size' , $data['samegoods'][0]['size']);
		$this->assign('store' , $data['samegoods'][0]['store']);
		$this->display();
	}

	// 加入购物车
	public function shopcart(){


		$get = I('get.');
		$get['ctime'] = time();
		
		$cart = M('cart');

		$user_id = $get['user_id'];
		$goods_id = $get['goods_id'];
		$num = $get['num'];
		$size = $get['size'];

		// 判断该商品是否已经存在购物车中
		$cart = M('cart');
		$mapcart['user_id'] = $user_id ;
		$mapcart['goods_id'] = $goods_id;
		$mapcart['size'] = $size;
		$mapcart['status'] = 0;

		$samecart = $cart->where($mapcart)->select();

		// 如果已经添加了就加数量
		if (count($samecart) > 0) {
			$res = $cart->where($mapcart)->setInc('num' , $num);
			echo $res;
		}else{
			$res = $cart->add($get);
			echo $res;
		}

		
	}


}
